﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WinNemoLib;
using System.Text;
using System.Data.SqlClient;
using System.Data;


namespace TireBias.Models
{
   public class BIASSUBPlanModel
   {
      public class BIASSUBPlan_DS
      {
         public string _biasno { get; set; }
         public string _plandt { get; set; }
         public string _itemno { get; set; }
         public string _sitemno { get; set; }
         public string _size { get; set; }

         public string _Ply1 { get; set; }
         public string _Ply2 { get; set; }
         public string _tPly1 { get; set; }
         public string _tPly2 { get; set; }
         public string _tPly3 { get; set; }
         public string _tPly4 { get; set; }
         public string _angPly1 { get; set; }
         public string _angPly2 { get; set; }
         public string _widthPly1 { get; set; }
         public string _widthPly2 { get; set; }
         public string _emnpname { get; set; }

         public string _Rundt { get; set; }
         public string _finflag { get; set; }
         public string _findat { get; set; }
         public string _empname { get; set; }
         public string _shift { get; set; }
         public string _sauthemp { get; set; }
         public string _sreatxt { get; set; }
         public string _sshtxt { get; set; }
 

      }
      public string GET_SEQ(string plandt, string biasno,string itemno)
      {
         int seq = 0;
         string ConnectionString = Nemo.GetConfiguredDbConnectionWrappertostring("Database");
         SqlConnection cnn = new SqlConnection(ConnectionString);
         StringBuilder str = new StringBuilder();
         str.AppendLine("select isnull(( select max(sitemno)iSub from ");
         str.AppendLine(Nemo.GetINI("Dbase", "Base") + ".[dbo].[BIASSUBPLAN]");
         str.AppendLine(" where  biasno=@biasno and plandt= convert(datetime, @plandt,120) and itemno=@itemno group by biasno,plandt,itemno ),0) + 1");
         SqlCommand cmd = new SqlCommand(str.ToString(), cnn);
         cmd.Connection.Open();
         cmd.CommandType = CommandType.Text;
         cmd.Parameters.Add("@plandt", SqlDbType.NVarChar).Value = DateUtil.ToInternalDate(plandt, WinNemoLib.DateUtil.eLanguage.EN);
         cmd.Parameters.Add("@biasno", SqlDbType.VarChar).Value = biasno;
         cmd.Parameters.Add("@itemno", SqlDbType.VarChar).Value = itemno;

         SqlDataAdapter my = new SqlDataAdapter();
         DataSet ds = new DataSet();
         my.SelectCommand = cmd;
         my.Fill(ds);

         if (ds.Tables[0].Rows.Count <= 0)
         {
            cmd.Connection.Close();
            return "1";
         }         
         return ds.Tables[0].Rows[0][0].ToString();
      }

      public Boolean Ins_Data(ConnectionWrapper cnn, BIASSUBPlan_DS incoming, string usernm)
      {
         try
         {
            StringBuilder comstr = new StringBuilder();
            comstr.AppendLine(" INSERT INTO ");
            comstr.AppendLine(Nemo.GetINI("Dbase", "Base") + ".[dbo].[BIASSUBPLAN]");
        

            comstr.AppendLine("( biasno,plandt,[itemno], [sitemno], [Ply1], [Ply2], [empname], [shift], [sauthemp], [sreatxt], [sshtxt])  ");
            comstr.AppendLine("VALUES( @biasno, convert(datetime, @plandt,120), @itemno,@sub ");

            comstr.AppendLine(", @Ply1,@Ply2, @empname," + Nemo.GetINI("Dbase", "Base") + ".[dbo].GET_SHIFT_PRD(getdate()) ,@sauthemp, @sreatxt,@sshtxt) ");

            CommandWrapper cmd = cnn.CreateCommand();
            cmd.CommandText = comstr.ToString();


            cmd.AddParameterStringWithValue("@biasno", incoming._biasno.Trim());
            cmd.AddParameterStringWithValue("@plandt", DateUtil.ToInternalDate(incoming._plandt, WinNemoLib.DateUtil.eLanguage.EN));
            cmd.AddParameterStringWithValue("@itemno", incoming._itemno);
            cmd.AddParameterStringWithValue("@sub", incoming._sitemno);
            cmd.AddParameterStringWithValue("@Ply1", incoming._Ply1);
            cmd.AddParameterStringWithValue("@Ply2", incoming._Ply2);

            cmd.AddParameterStringWithValue("@empname", usernm);
            //cmd.AddParameterStringWithValue("@shift", incoming._shift);
            cmd.AddParameterStringWithValue("@sauthemp", incoming._sauthemp);
            cmd.AddParameterStringWithValue("@sreatxt", incoming._sreatxt);
            cmd.AddParameterStringWithValue("@sshtxt", incoming._sshtxt);


            if (cmd.ExecuteNonQuery() <= 0)
            {
               cnn.RollbackTransaction();
               return false;
            }

            return true;
         }
         catch (Exception ex)
         {
            return false;
            throw ex;
         }

      }

      public List<BIASSUBPlan_DS> SEL_HEAD_NOFIN(string biasno, string plandt, string itemno)
      {

          string ConnectionString = Nemo.GetConfiguredDbConnectionWrappertostring("Database");
          SqlConnection cnn = new SqlConnection(ConnectionString);
          StringBuilder str = new StringBuilder();

          str.AppendLine(" select t.biasno, t.plandt, t.itemno, sitemno, Ply1, Ply2,angPly1,angPly2, t.Rundt, b.finflag, t.findat, t.empname, t.shift, t.sauthemp, t.sreatxt, t.sshtxt,smpemp ,smWidth1,smWidth2");

          str.AppendLine(" from " + Nemo.GetINI("Dbase", "Base") + ".dbo.BIASSUBPLAN t");
          str.AppendLine(" left join " + Nemo.GetINI("Dbase", "Base") + ".dbo.BIASPLAN b on t.biasno=b.biasno and t.plandt =b.plandt and t.itemno =b.itemno ");


          str.AppendLine(" where ( b.findat is null or b.actflag is null ) and t.biasno=@biasno");
          if (StrUtil.IsNotEmpty(plandt))
          {
              str.AppendLine(" and t.plandt=convert(datetime,@plndt,120) ");
          }
          if (StrUtil.IsNotEmpty(itemno))
          {
              str.AppendLine(" and t.itemno=@itemno");
          }

          SqlCommand cmd = new SqlCommand(str.ToString() + " order by angPly1", cnn);
          cmd.Connection.Open();
          cmd.CommandType = CommandType.Text;


          cmd.Parameters.Add("@biasno", SqlDbType.VarChar).Value = biasno;
          if (StrUtil.IsNotEmpty(plandt)) cmd.Parameters.Add("@plndt", SqlDbType.VarChar).Value = DateUtil.ToInternalDate(plandt, WinNemoLib.DateUtil.eLanguage.EN);
          if (StrUtil.IsNotEmpty(itemno)) cmd.Parameters.Add("@itemno", SqlDbType.VarChar).Value = itemno;

          SqlDataAdapter my = new SqlDataAdapter();
          DataSet ds = new DataSet();
          my.SelectCommand = cmd;
          my.Fill(ds);

          List<BIASSUBPlan_DS> list = new List<BIASSUBPlan_DS>();
          if (ds.Tables[0].Rows.Count <= 0)
          {
              cmd.Connection.Close();
              return list;
          }
          for (int cuIndex = 0; cuIndex < ds.Tables[0].Rows.Count; cuIndex++)
          {
              DataRow items = ds.Tables[0].Rows[cuIndex];
              BIASSUBPlan_DS model = new BIASSUBPlan_DS();
              model._biasno = items["biasno"].ToString();
              model._itemno = items["itemno"].ToString();
              model._sitemno = items["sitemno"].ToString();
              model._Ply1 = items["Ply1"].ToString();
              model._Ply2 = items["Ply2"].ToString();
              model._angPly1 = items["angPly1"].ToString();
              model._angPly2 = items["angPly2"].ToString();
              model._finflag = items["finflag"].ToString();
              model._plandt = DateUtil.ToDisplayDate(items["plandt"], DateUtil.eLanguage.EN);
              model._Rundt = DateUtil.ToDisplayDateTime(items["Rundt"], DateUtil.eLanguage.EN);
              model._empname = items["empname"].ToString();
              model._shift = items["shift"].ToString();
              model._widthPly1 = items["smWidth1"].ToString();
              model._widthPly2 = items["smWidth2"].ToString();
              model._sauthemp = items["smpemp"].ToString();//sample athu.

              list.Add(model);
          }
          return list;
      }


      public List<BIASSUBPlan_DS> SEL_SUB_NOFIN(string biasno,string plandt,  string itemno)
      {

         string ConnectionString = Nemo.GetConfiguredDbConnectionWrappertostring("Database");
         SqlConnection cnn = new SqlConnection(ConnectionString);
         StringBuilder str = new StringBuilder();

         str.AppendLine(" select t.biasno, t.plandt, t.itemno, sitemno, Ply1, Ply2,angPly1,angPly2, t.Rundt, b.finflag, t.findat, t.empname, t.shift, t.sauthemp, t.sreatxt, t.sshtxt,smpemp");
         
         str.AppendLine(" from " + Nemo.GetINI("Dbase", "Base") + ".dbo.BIASSUBPLAN t");
         str.AppendLine(" left join " + Nemo.GetINI("Dbase", "Base") + ".dbo.BIASPLAN b on t.biasno=b.biasno and t.plandt =b.plandt and t.itemno =b.itemno ");

         
         str.AppendLine(" where (t.Rundt is null or t.findat is null) and t.biasno=@biasno");
         if (StrUtil.IsNotEmpty(plandt))
         {
            str.AppendLine(" and t.plandt=convert(datetime,@plndt,120) ");
         }
         if (StrUtil.IsNotEmpty(itemno))
         {
            str.AppendLine(" and t.itemno=@itemno");
         }

         SqlCommand cmd = new SqlCommand(str.ToString() + " order by angPly1", cnn);
         cmd.Connection.Open();
         cmd.CommandType = CommandType.Text;


              cmd.Parameters.Add("@biasno", SqlDbType.VarChar).Value = biasno;   
         if (StrUtil.IsNotEmpty(plandt)) cmd.Parameters.Add("@plndt", SqlDbType.VarChar).Value = DateUtil.ToInternalDate(plandt, WinNemoLib.DateUtil.eLanguage.EN); 
         if (StrUtil.IsNotEmpty(itemno)) cmd.Parameters.Add("@itemno", SqlDbType.VarChar).Value = itemno;

         SqlDataAdapter my = new SqlDataAdapter();
         DataSet ds = new DataSet();
         my.SelectCommand = cmd;
         my.Fill(ds);

         List<BIASSUBPlan_DS> list = new List<BIASSUBPlan_DS>();
         if (ds.Tables[0].Rows.Count <= 0)
         {
            cmd.Connection.Close();
            return list;
         }
         for (int cuIndex = 0; cuIndex < ds.Tables[0].Rows.Count; cuIndex++)
         {
            DataRow items = ds.Tables[0].Rows[cuIndex];
            BIASSUBPlan_DS model = new BIASSUBPlan_DS();
            model._biasno = items["biasno"].ToString();
            model._itemno = items["itemno"].ToString();
            model._sitemno = items["sitemno"].ToString();
            model._Ply1 = items["Ply1"].ToString();
            model._Ply2 = items["Ply2"].ToString();
            model._angPly1 = items["angPly1"].ToString();
            model._angPly2 = items["angPly2"].ToString();
            model._finflag = items["finflag"].ToString();
            model._plandt = DateUtil.ToDisplayDate(items["plandt"], DateUtil.eLanguage.EN);
            model._Rundt = DateUtil.ToDisplayDateTime(items["Rundt"], DateUtil.eLanguage.EN);
            model._empname = items["empname"].ToString();
            model._shift = items["shift"].ToString();

            model._sauthemp = items["smpemp"].ToString();//sample athu.

            list.Add(model);
         }
         return list;
      }

      public Boolean DEL_SUB_BIAS(ConnectionWrapper cnn, string dtPlan, string biasno,string itemno ,string subItem)
      {
          try
          {
              StringBuilder comstr = new StringBuilder();
              comstr.AppendLine(" DELETE ");
              comstr.AppendLine(Nemo.GetINI("Dbase", "Base") + ".[dbo].[BIASSUBPLAN]");
              comstr.AppendLine(" where plandt=convert(datetime,@plndt,120) and biasno=@biasno and sitemno=@sitemno ");
              comstr.AppendLine(" and itemno=@itemno ");

              CommandWrapper cmd = cnn.CreateCommand();
              cmd.CommandText = comstr.ToString();
              cmd.AddParameterStringWithValue("@plndt", DateUtil.ToInternalDate(dtPlan, WinNemoLib.DateUtil.eLanguage.EN));
              cmd.AddParameterStringWithValue("@biasno", biasno);
              cmd.AddParameterStringWithValue("@sitemno", subItem);
              cmd.AddParameterStringWithValue("@itemno", itemno);             

              cmd.ExecuteNonQuery();

              return true;
          }
          catch (Exception ex)
          {
              return false;
              throw ex;
          }

      }

      public Boolean UPDATE_SUB_STATUS_BIAS(ConnectionWrapper cnn, BIASSUBPlan_DS data,string TypeStatus="R",Boolean blnSample = false)
      {
          try
          {
              StringBuilder comstr = new StringBuilder();
              comstr.AppendLine(" UPDATE ");
              comstr.AppendLine(Nemo.GetINI("Dbase", "Base") + ".[dbo].[BIASSUBPLAN]");
              if (TypeStatus == "R")
              {
                  comstr.AppendLine(" SET Rundt=getdate() ");
           
              }
              if (TypeStatus == "SM")
              {
                  comstr.AppendLine(" SET Rundt=getdate() ");
                  comstr.AppendLine(" , angPLY1=@ply1,angPLY2=@ply2 ,smWidth1=@w1 ,smWidth2=@w2 ");
              }

              if (TypeStatus == "AN")
              {
                  comstr.AppendLine(" SET angPLY1=@ply1,angPLY2=@ply2 ");
              }
              if (TypeStatus == "F")
              {
                  comstr.AppendLine(" SET findat=getdate(),finflag='X' ");
              }
              comstr.AppendLine(" where plandt=convert(datetime,@plndt,120) and biasno=@biasno and sitemno=@sitemno ");
              comstr.AppendLine(" and itemno=@itemno ");

              CommandWrapper cmd = cnn.CreateCommand();
              cmd.CommandText = comstr.ToString();
              cmd.AddParameterStringWithValue("@plndt", DateUtil.ToInternalDate(data._plandt, WinNemoLib.DateUtil.eLanguage.EN));
              cmd.AddParameterStringWithValue("@biasno", data._biasno);
              cmd.AddParameterStringWithValue("@sitemno", data._sitemno);
              cmd.AddParameterStringWithValue("@itemno", data._itemno);

              if ((TypeStatus == "AN")||(TypeStatus == "SM"))
              {
                  cmd.AddParameterStringWithValue("@ply1", data._Ply1);
                  cmd.AddParameterStringWithValue("@ply2", data._Ply2);
              }
              if (TypeStatus == "SM")
              {
                  cmd.AddParameterStringWithValue("@w1", data._widthPly1);
                  cmd.AddParameterStringWithValue("@w2", data._widthPly2);
              }

              if (cmd.ExecuteNonQuery() <= 0)
              {
                  return false;
              }

              if (TypeStatus == "R" )
              {
                  if (data._sitemno == "1")
                  {
                      comstr = new StringBuilder();
                      comstr.AppendLine(" INSERT ");
                      comstr.AppendLine(Nemo.GetINI("Dbase", "LOG") + ".[dbo].[BIASPLAN] ");
                      comstr.AppendLine(" SELECT * from");
                      comstr.AppendLine(Nemo.GetINI("Dbase", "Base") + ".[dbo].[BIASPLAN] ");

                      comstr.AppendLine(" where Plansts='L' and plandt = convert(datetime,@plndt,120) ");
                      comstr.AppendLine(" and  convert(float,itemno) = convert(float," + data._itemno + ") ");
                      comstr.AppendLine(" and biasno= " + data._biasno);
                      cmd = cnn.CreateCommand();
                      cmd.CommandText = comstr.ToString();

                      cmd.AddParameterStringWithValue("@plndt", DateUtil.ToInternalDate(data._plandt, WinNemoLib.DateUtil.eLanguage.EN));


                      if (cmd.ExecuteNonQuery() <= 0)
                      {
                          return false;
                      }
                  }
                  comstr = new StringBuilder();
                  comstr.AppendLine(" INSERT ");
                  comstr.AppendLine(Nemo.GetINI("Dbase", "LOG") + ".[dbo].[BIASSUBPLAN] ");
                  comstr.AppendLine(" SELECT * from");
                  comstr.AppendLine(Nemo.GetINI("Dbase", "Base") + ".[dbo].[BIASSUBPLAN] ");

                  comstr.AppendLine(" where plandt = convert(datetime,@plndt,120) ");
                  comstr.AppendLine(" and  convert(float,itemno) = convert(float," + data._itemno + ") and sitemno=@sitemno");
                  comstr.AppendLine(" and biasno= " + data._biasno); 
              
                  cmd = cnn.CreateCommand();
                  cmd.CommandText = comstr.ToString();
                  cmd.AddParameterStringWithValue("@sitemno", data._sitemno);
                  cmd.AddParameterStringWithValue("@plndt", DateUtil.ToInternalDate(data._plandt, WinNemoLib.DateUtil.eLanguage.EN));
                  if (cmd.ExecuteNonQuery() <= 0)
                  {
                      return false;
                  }

              }
              return true;
          }
          catch (Exception ex)
          {
              return false;
              throw ex;
          }

      }

      public Boolean UPDATE_LEN_BIAS(ConnectionWrapper cnn, BIASSUBPlan_DS data)
      {
          try
          {
              StringBuilder comstr = new StringBuilder();
              comstr.AppendLine(" UPDATE ");
              comstr.AppendLine(Nemo.GetINI("Dbase", "Base") + ".[dbo].[BIASPLAN]");
 
                comstr.AppendLine(" SET ");
                comstr.AppendLine("P1=@plyLen1,");
                comstr.AppendLine("P2=@plyLen2,");
                comstr.AppendLine("P3=@plyLen3,");
                comstr.AppendLine("P4=@plyLen4");
              
                comstr.AppendLine(" where plandt=convert(datetime,@plndt,120) and biasno=@biasno  ");
                comstr.AppendLine(" and itemno=@itemno ");

              CommandWrapper cmd = cnn.CreateCommand();
                cmd.CommandText = comstr.ToString();
                cmd.AddParameterStringWithValue("@plndt", DateUtil.ToInternalDate(data._plandt, WinNemoLib.DateUtil.eLanguage.EN));
                cmd.AddParameterStringWithValue("@biasno", data._biasno);          
                cmd.AddParameterStringWithValue("@itemno", data._itemno);

          
                cmd.AddParameterStringWithValue("@plyLen1", data._tPly1);
                cmd.AddParameterStringWithValue("@plyLen2", data._tPly2);
                cmd.AddParameterStringWithValue("@plyLen3", data._tPly3);
                cmd.AddParameterStringWithValue("@plyLen4", data._tPly4);
          

              if (cmd.ExecuteNonQuery() <= 0)
              {
                  return false;
              }

              return true;
          }
          catch (Exception ex)
          {
              return false;
              throw ex;
          }

      }


      public List<TireBias.Models.KANBANPlanModel.KANBANPlan_DS> GET_KANBANPLAN_SUB(string biasno, string dtpln = "", string itemno = "", string sub = "",Boolean NoFin=false)
      {

          string ConnectionString = Nemo.GetConfiguredDbConnectionWrappertostring("Database");
          SqlConnection cnn = new SqlConnection(ConnectionString);
          StringBuilder str = new StringBuilder();

          str.AppendLine(" select  b.*,a.sitemno,ply1,ply2,rundt,a.finflag,a.findat,a.empname,a.shift,c.modifyby stdBY,c.modifydt stdDT,d.modifyby infBy,d.modifydt infDT ");
          str.AppendLine(",c.validFrom stdFr,c.validTo stdTo ,d.validFrom infFr,d.validTo infTo ,angle ,angPly1 ");
          str.AppendLine(" from " + Nemo.GetINI("Dbase", "Base") + ".dbo.BIASSUBPLAN a ");
          str.AppendLine(" LEFT Join " + Nemo.GetINI("Dbase", "Base") + ".dbo.BIASPLAN b on a.biasno=b.biasno and a.plandt=b.plandt and a.itemno=b.itemno ");
          str.AppendLine(" LEFT JOIN " + Nemo.GetINI("Dbase", "TIRSTD") + ".dbo.TIRSTD c  ");
          str.AppendLine("  on b.Sizes=c.sizes and b.topcrdcd=c.TireCode and b.Forming=c.forming   and getdate() between c.validfrom and c.validto");
          str.AppendLine(" LEFT JOIN (select distinct tireid,angle,ply  from  " + Nemo.GetINI("Dbase", "TIRSTD") + ".dbo.TIRSTD_des)e on c.tireid=e.tireid and 'P'+e.ply=ply1 ");
          str.AppendLine(" LEFT JOIN " + Nemo.GetINI("Dbase", "TIRSTD") + ".dbo.TIRSTD_INF d  ");
          str.AppendLine("  on c.tireid=d.tireid ");

          str.AppendLine(" where a.biasno=@biasno");

          if (NoFin) {
              str.AppendLine(" and a.finflag is null ");
          }

          if (StrUtil.IsNotEmpty(dtpln))
          {
              str.AppendLine(" and a.plandt=convert(datetime,@plndt,120) ");
          }

          if (StrUtil.IsNotEmpty(itemno))
          {
              str.AppendLine(" and a.itemno=@itemno ");
          }
          if (StrUtil.IsNotEmpty(sub))
          {
              str.AppendLine(" and a.sitemno=@sitemno ");
          }

          SqlCommand cmd = new SqlCommand(str.ToString(), cnn);
          cmd.Connection.Open();
          cmd.CommandType = CommandType.Text;

          if (StrUtil.IsNotEmpty(dtpln))
          {
              cmd.Parameters.Add("@plndt", SqlDbType.VarChar).Value = DateUtil.ToInternalDate(dtpln, WinNemoLib.DateUtil.eLanguage.EN);
          }

          if (StrUtil.IsNotEmpty(itemno))
          {
              cmd.Parameters.Add("@itemno", SqlDbType.VarChar).Value = itemno;
          }

          if (StrUtil.IsNotEmpty(sub))
          {
              cmd.Parameters.Add("@sitemno", SqlDbType.VarChar).Value = sub;
          }
          cmd.Parameters.Add("@biasno", SqlDbType.VarChar).Value = biasno;

          SqlDataAdapter my = new SqlDataAdapter();
          DataSet ds = new DataSet();
          my.SelectCommand = cmd;
          my.Fill(ds);

          List<TireBias.Models.KANBANPlanModel.KANBANPlan_DS> list = new List<TireBias.Models.KANBANPlanModel.KANBANPlan_DS>();
          if (ds.Tables[0].Rows.Count <= 0)
          {
              cmd.Connection.Close();
              return list;
          }
          for (int cuIndex = 0; cuIndex < ds.Tables[0].Rows.Count; cuIndex++)
          {
              DataRow items = ds.Tables[0].Rows[cuIndex];
              TireBias.Models.KANBANPlanModel.KANBANPlan_DS model = new TireBias.Models.KANBANPlanModel.KANBANPlan_DS();
              model._biasno = items["biasno"].ToString();
              model._itemno = items["itemno"].ToString();
              model._topcrdcd = items["topcrdcd"].ToString();
              model._sizes = items["sizes"].ToString();
              model._forming = items["Forming"].ToString();
              model._plandt = DateUtil.ToDisplayDate(items["plandt"], DateUtil.eLanguage.EN);
              model._topexp = DateUtil.ToDisplayDate(items["topexp"], DateUtil.eLanguage.EN);
              //model._pP1 = items["P1"].ToString();
              //model._pP2 = items["P2"].ToString();
              //model._pP3 = items["P3"].ToString();
              //model._pP4 = items["P4"].ToString();
              model._P1 = items["P1"].ToString();
              model._P2 = items["P2"].ToString();
              model._P3 = items["P3"].ToString();
              model._P4 = items["P4"].ToString();
              //model._Uptdat = DateUtil.ToDisplayDateTime(items["Uptdat"], DateUtil.eLanguage.EN);
              //model._Uptemp = items["Uptemp"].ToString();
              model._Text = items["text"].ToString();

              //model._empname = items["empname"].ToString();
              model._shift = items["shift"].ToString();
              //model._finflag = items["finflag"].ToString();
              //model._findat = DateUtil.ToDisplayDateTime(items["findat"], DateUtil.eLanguage.EN);
              model._Tcrdlot = items["tcrdlot"].ToString();
              model._toproll = items["toproll"].ToString();
              //model._topexp = DateUtil.ToDisplayDateTime(items["Uptdat"], DateUtil.eLanguage.EN);
              model._toplen = items["toplen"].ToString();
              //model._topauthemp = items["topauthemp"].ToString();
              //model._topreatxt = items["topreatxt"].ToString();
              //model._topshtxt = items["topshtxt"].ToString();
              model._TmpP1 = items["ply1"].ToString();
              model._TmpP2 = items["ply2"].ToString();
              model._subItem = items["sitemno"].ToString();
              model._fileSTDModifyBy = items["stdBy"].ToString();
              model._fileSTDModifyDT = DateUtil.ToDisplayDateTime(items["stdDT"], DateUtil.eLanguage.EN);
              model._fileINFModifyBy = items["infBy"].ToString();
              model._fileINFModifyDT = DateUtil.ToDisplayDateTime(items["infDT"], DateUtil.eLanguage.EN);
              model._STDvalid = DateUtil.ToDisplayDateTime(items["stdFr"], DateUtil.eLanguage.EN) + "-" + DateUtil.ToDisplayDateTime(items["stdTo"], DateUtil.eLanguage.EN);
              model._INFvalid = DateUtil.ToDisplayDateTime(items["infFr"], DateUtil.eLanguage.EN) + "-" + DateUtil.ToDisplayDateTime(items["infTo"], DateUtil.eLanguage.EN);
              model._Angel = items["angle"].ToString();
              model._angPly1 = items["angPly1"].ToString();
              list.Add(model);
          }
          return list;
      }
   }
}